package com.moli.iov.his.remote.impl;


import com.moli.iov.his.dto.VehicleTrajectoryReqDTO;
import com.moli.iov.his.dto.VehicleTrajectoryResDTO;
import com.moli.iov.his.remote.HistoryRemoteService;
import com.moli.iov.his.remote.VehicleTrajectoryService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.vehicle.service.IVehicleBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @ClassName HistoryRemoteServiceImpl
 * @Description TODO
 * @Author 李伟松
 * @CreateDate 2019-09-09 下午 1:45
 * @UpdateDate 2019-09-09 下午 1:45
 * @Version 1.0
 */
@Service("historyRemoteService")
@Slf4j
public class HistoryRemoteServiceImpl implements HistoryRemoteService {

    @Resource
    VehicleTrajectoryService vehicleTrajectoryService;

    /**
     * 轨迹查询-主方法
     * @param dto
     * @return
     */
    @Override
    public RestResponse<List<VehicleTrajectoryResDTO>> listVehicleTrajectory(VehicleTrajectoryReqDTO dto) {
        List<VehicleTrajectoryResDTO> list = vehicleTrajectoryService.listVehicleTrajectory(dto);
        Collections.sort(list, new Comparator<VehicleTrajectoryResDTO>() {
            @Override
            public int compare(VehicleTrajectoryResDTO o1, VehicleTrajectoryResDTO o2) {
                // 按照学生的年龄进行升序排列
                if (o1.getReportDate().getTime() > o2.getReportDate().getTime()) {
                    return 1;
                }
                if (o1.getReportDate().getTime() == o2.getReportDate().getTime()) {
                    return 0;
                }
                return -1;
            }
        });

        return RestResponse.success(list);
    }


}
